cmake_minimum_required(VERSION 3.10)
project(BlogSystem VERSION 1.0)

# C++17标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 编译选项
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pthread")

# 输出目录
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# 添加头文件目录
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

# 查找必要的依赖库
# find_package(MySQL REQUIRED)
include_directories(/usr/include/mysql)
link_directories(/usr/lib/mysql)

# find_package(hiredis REQUIRED)
include_directories(/usr/include/hiredis)
link_directories(/usr/lib/x86_64-linux-gnu)

# find_package(rdkafka REQUIRED)
include_directories(/usr/include/librdkafka)
link_directories(/usr/lib/x86_64-linux-gnu)

# 添加nlohmann-json支持
# 注意：系统安装位置可能是/usr/include/nlohmann，但实际文件是/usr/include/nlohmann/json.hpp
include_directories(/usr/include)
# 如果有需要，也可以尝试以下备选路径
# include_directories(/usr/local/include)
# include_directories(/usr/include/nlohmann)

# 添加子目录
add_subdirectory(src/common)
add_subdirectory(src/network)
add_subdirectory(src/database)
add_subdirectory(src/cache)
add_subdirectory(src/messaging)
add_subdirectory(src/service)

# 添加示例代码
add_subdirectory(examples)

# 注意: 不要在这里定义可执行文件,因为子目录中已经定义了
# 服务可执行文件在src/service/*/CMakeLists.txt中已定义

# 单元测试
add_subdirectory(tests)

# 安装规则
# 使用TARGETS命令安装子目录中定义的目标
install(TARGETS 
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)

# 安装头文件
install(DIRECTORY include/ DESTINATION include/blog_system)

# export MySQL_DIR=/path/to/mysql/installation

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") 